package top.laoshuzi.rpi3

import lib.bcm2835.bcm2835_delay

fun reduce(pwm: Pwm, data: Int) {

    var d = data

    pwm.setData(d.toUInt(), d.toUInt())

    var t = 10;
    while (t-- >= 0) {
        d = d * 3 / 5
        pwm.setData(d.toUInt())
        bcm2835_delay(50)
    }
}

fun main(args: Array<String>) {

/*    var bcm2835Manager: Bcm2835Manager = Bcm2835Manager.INSTANCE
    val pwm = Pwm.INSTANCE

    val pwmMusic = PwmMusic()
    val data: Array<Int> = arrayOf(
            pwmMusic.getDate(1, 0),
            pwmMusic.getDate(2, 0),
            pwmMusic.getDate(3, 0),
            pwmMusic.getDate(4, 0),
            pwmMusic.getDate(5, 0),
            pwmMusic.getDate(6, 0),
            pwmMusic.getDate(7, 0),
            pwmMusic.getDate(1, 1),
            pwmMusic.getDate(2, 1),
            pwmMusic.getDate(3, 1),
            pwmMusic.getDate(4, 1),
            pwmMusic.getDate(5, 1),
            pwmMusic.getDate(6, 1),
            pwmMusic.getDate(7, 1),
            pwmMusic.getDate(1, 2),
            pwmMusic.getDate(2, 2),
            pwmMusic.getDate(3, 2),
            pwmMusic.getDate(4, 2),
            pwmMusic.getDate(5, 2),
            pwmMusic.getDate(6, 2),
            pwmMusic.getDate(7, 2)
    )

    for (i in data) {
//        pwm.setData(i.toUInt(), 5U)
//        bcm2835_delay(500)
        reduce(pwm, i)
    }

    pwm.setData(0U)

    bcm2835Manager.close()*/


    var bcm2835Manager: Bcm2835Manager = Bcm2835Manager.INSTANCE

    var range = args[0].toInt()
    var data = args[1].toInt()

    val pwm = Pwm.INSTANCE
    pwm.setData(range.toUInt(), data.toUInt())


    while (true) {
        pwm.setData(data.toUInt())
        bcm2835_delay(500)
        pwm.setData(0U)
        bcm2835_delay(500)
    }

    bcm2835Manager.close()
}